﻿<?php
defined( '_JEXEC' ) or die( 'Restricted access' );

$editor = &JFactory::getEditor();
JFilterOutput::objectHTMLSafe( $this->item );
JHTML::_('behavior.calendar');
JHTML::_('behavior.modal', 'a.modal');
$document	=& JFactory::getDocument();
$link = JRoute::_( 'index.php?option=com_ecommerce&controller=products&task=delete_img&id='. $this->product->id );
?>
<script language="javascript">
function checkname(){
	if($('task').value!="cancel"){
		if (document.adminForm.name.value == ''){
			alert('Không thể để trống tên sản phẩm');
			return false;
		}
	}
	
}
function addRelatedProducts(element){
	if($(element.id)){
		alert('"'+element.title + '" đã chọn'); 
		return false;
	}
	else{
		$('related_list').adopt(element);
		return true;
	}
}
function remove_related_product(id){
	try{
		$('related_list').removeChild($('related_'+id));
		$('related_list').removeChild($('input_related_'+id));

	}catch(err){}
}

</script>


<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data" onsubmit="return checkname()">
  <div class="col100">
  <fieldset class="adminform">
  <legend><?php echo JText::_( 'Quản lí thông tin sản phẩm' ); ?></legend>
  <table class="admintable">
    <tr>
      <td width="200" align="right" class="key"><label for="title_on_link"> <?php echo JText::_( 'Tên sản phẩm' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="name" id="name" size="32" maxlength="250" value="<?php echo htmlspecialchars($this->product->name);?>" />
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Giá' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="price" id="price" size="32" maxlength="250" value="<?php echo $this->product->price;?>" />
      </td>
    </tr>
	 <tr>
      <td width="200" align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Giá khuyến mãi' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="promotion_price" id="promotion_price" size="32" maxlength="250" value="<?php echo $this->product->promotion_price;?>" />
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Số luợng' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="quantity" id="quantity" size="32" maxlength="250" value="<?php echo $this->product->quantity;?>" />
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="desc_on_link"> <?php echo JText::_( 'Phân loại sản phẩm' ); ?>: </label>
      </td>
      <td><select name="cat_id">
          <option value="0">--Chọn phân lọai--</option>
            <?php echo $this->catoption; ?>
         
        </select>
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="desc_on_link"> <?php echo JText::_( 'Nhà sản xuất' ); ?>: </label>
      </td>
      <td><select name="company" id="company">
          <option value='0'>--Select a company--</option>
          <?php
						$db =& JFactory::getDBO();
						$query = "select * from #__pr_company where published=1";
						$db->setQuery($query);
						if($rows = $db->loadObjectList()){
							foreach($rows as $row){
								if($this->product->company_id == $row->id){
									echo "<option selected='selected' value='".$row->id."'>".$row->name."</option>";
								} else {
									echo "<option value='".$row->id."'>".$row->name."</option>";
								}
							}
						}
					?>
        </select>
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="desc_on_link">Mô tả sơ lược: </label>
      </td>
      <td><?php echo $editor->display( 'description', $this->product->description , '100%', '150', '75', '20' ) ; ?> </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="desc_on_link">Mô tả chi tiết: </label>
      </td>
      <td><?php echo $editor->display( 'description_en', $this->product->description_en, '100%', '150', '75', '20' ) ; ?> </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="desc_on_link"> <?php echo JText::_( 'Bảo hành' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="warranty" id="warranty" size="32" maxlength="250" value="<?php echo $this->product->warranty;?>" />
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="desc_on_link"> <?php echo JText::_( 'Thuế(%)' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="tax" id="tax" size="32" maxlength="250" value="<?php echo $this->product->tax;?>" />
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="desc_on_link"> <?php echo JText::_( 'Published' ); ?>: </label>
      </td>
      <td><?php if ($this->product->published ==1 ){ ?>
        <input type="radio" name="published" value="1" checked="checked" />
        Hiện
        <input type="radio" name="published" value="0" />
        Ẩn
        <?php } else { ?>
        <input type="radio" name="published" value="1"  />
        Hiện
        <input type="radio" name="published" value="0" checked="checked" />
        Ẩn
        <?php } ?>
      </td>
    </tr>
	
	<tr>
		<td width="200" align="right" class="key">Sản phẩm liên quan : </td>
        <td>
        <div id="related_list">
			<?php 
				if(count($this->product->related)>0){
					foreach($this->product->related as $related){
						echo "<div class='related_products' title='".$related->name."' id='related_$related->id'> ".$related->name."  <a href='#' onclick='remove_related_product($related->id); return false;'>[Xóa]</a></div>";
						echo '<input type="hidden" id="input_related_'.$related->id.'" name="input_related[]" value="'. $related->id.'" />';
					}
				}
			?>
        
        </div> 
        <a class="modal" rel="{handler: 'iframe', size: {x: 700, y: 350}}" href="index.php?option=com_ecommerce&controller=products&layout=related&tmpl=component&reset=1">	Chọn sản phẩm</a>
        </td>
	</tr>

	<tr>
		<td width="200" align="right" class="key"><?php echo JText::_( 'Video link' ); ?>
		</td>
		<td>
	<textarea  class="text_area" name="videolink" id="videolink" cols="55" > <?php echo $this->product->videolink;?></textarea>
		</td>
	</tr>
    <tr>
      <td width="200" align="right" class="key">Hình mặc định:</td>
      <td><?php $dir = $this->product->id+999-(($this->product->id-1)%1000); 
	  	if(trim($this->product->image)):
	  ?>
        <img src="<?php echo '../'.$this->params->get('imgpath').$dir.'/'.$this->product->id.'/thumb_'.$this->product->image; ?>" width="150" border="0" align="middle" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link;?>"><img src="images/publish_x.png" align="absmiddle" />Xóa</a>
		<?php endif;?>
		<input type="hidden" name="image" value="<?php echo $this->product->image; ?>" /></td>
    </tr>
    
    <tr>
      <td width="200" align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Default Image ' ); ?>: </label>
      </td>
      <td><input type="file" name="txthinh" id="txthinh" size="32"  value="" />
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key">Hình 1:</td>
      <td><?php if(trim($this->product->image1)): ?>
        <img src="<?php echo '../'.$this->params->get('imgpath').$dir.'/'.$this->product->id.'/'.$this->product->image1; ?>" border="0" width="150" align="middle" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link.'&hinh=1';?>"><img src="images/publish_x.png" align="absmiddle" />Xóa</a>
		<?php endif;?>
		
        <input type="hidden" name="image1" value="<?php echo $this->product->image1; ?>">
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Image 1' ); ?>: </label>
      </td>
      <td><input type="file" name="txthinh1" id="txthinh1" size="32"  value="" />
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key">Hình 2:</td>
      <td><?php if(trim($this->product->image2)): ?>
        <img src="<?php echo '../'.$this->params->get('imgpath').$dir.'/'.$this->product->id.'/'.$this->product->image2; ?>" border="0" width="150" align="middle" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link.'&hinh=2';?>"><img src="images/publish_x.png" align="absmiddle" />Xóa</a>
		<?php endif;?>
        <input type="hidden" name="image2" value="<?php echo $this->product->image2; ?>">
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Image 2' ); ?>: </label>
      </td>
      <td><input type="file" name="txthinh2" id="txthinh2" size="32"  value="" />
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key">Hình 3:</td>
      <td><?php if(trim($this->product->image3)): ?>
        <img src="<?php echo '../'.$this->params->get('imgpath').$dir.'/'.$this->product->id.'/'.$this->product->image3; ?>" border="0" width="150" align="middle" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link.'&hinh=3';?>"><img src="images/publish_x.png" align="absmiddle" />Xóa</a>
        <?php endif;?>
        <input type="hidden" name="image3" value="<?php echo $this->product->image3; ?>">
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Image 3' ); ?>: </label>
      </td>
      <td><input type="file" name="txthinh3" id="txthinh3" size="32"  value="" />
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key">Hình 4:</td>
      <td><?php if(trim($this->product->image4)): ?>
        <img src="<?php echo '../'.$this->params->get('imgpath').$dir.'/'.$this->product->id.'/'.$this->product->image4; ?>" border="0" width="150" align="middle" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link.'&hinh=4';?>"><img src="images/publish_x.png" align="absmiddle" />Xóa</a>
        <?php endif;?>
        <input type="hidden" name="image4" value="<?php echo $this->product->image4; ?>">
      </td>
    </tr>
    <tr>
      <td width="200" align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Image 4' ); ?>: </label>
      </td>
      <td><input type="file" name="txthinh4" id="txthinh4" size="32"  value="" />
      </td>
    </tr>
  </table>

  </fieldset>
  </div>
  <div class="clr"></div>
  <input type="hidden" name="option" value="com_ecommerce" />
  <input type="hidden" name="id" value="<?php echo $this->product->id; ?>" />
  <input type="hidden" name="task" id="task" value="" />
  <input type="hidden" name="listcat" value="" />
  <input type="hidden" name="controller" value="products" />
</form>
